package app.netant.book.geilixsw;

import org.jsoup.select.Elements;

import app.netant.book.base.BaseDetail;

public class GeilixswDetail extends BaseDetail {

	public GeilixswDetail(String netSite) {
		super(netSite);
		this.preHref = "http://www.geilixsw.com";
	}

	@Override
	public void analyseTitle() {
		Elements parts = this.select("#maininfo .coverecom #bookinfo .bookright .booktitle h1");
		if(parts.size()>0){
			String title = parts.get(0).text();
			System.out.println("【Title】:"+title);
			this.entity.setNovelName(title);
			this.entity.setNovelFullName(title+".txt");
		}
		
		Elements authParts = this.select("#maininfo .coverecom #bookinfo .bookright .booktitle #author");
		if(authParts.size()>0){
			String writers = authParts.get(0).text();
			int idx = writers.indexOf("：");
			if(idx>0){
				String writer = writers.substring(idx+1);
				System.out.println("【Writer】:"+writer);
				this.entity.setNovelWriter(writer);
			}
		}
	}

	@Override
	public void analyseTags() {
		
		Elements parts = this.select("#maininfo .coverecom #bookinfo .bookright #count");
		if(parts.size()>0){
			String tags = parts.get(0).text();
			this.splitTags(tags,true);
		}
		
	}

	@Override
	public void analyseMemo() {
		Elements parts = this.select("#maininfo .coverecom #bookinfo .bookright #bookintro p");
		if(parts.size()>0){
			String memo = parts.get(0).text();
			System.out.println("【Memo】:"+memo);
			this.entity.setNovelMemo(memo);
		}
	}

	@Override
	public void analyseHref() {
		Elements parts = this.select("#maininfo .coverecom #bookinfo .motion a");
		for(int i=0;i<parts.size();i++){
			String text = parts.get(i).text();
			if("TXT下载".equals(text)){
				String href = parts.get(i).attr("href");
				if(href.startsWith("/")){
					href = "http://www.geilixsw.com"+href;
				}
				System.out.println("【Href】:"+href);
				this.entity.setDownPath(href);
				break;
			}
		}
	}
	
	@Override
	public void analyseType() {
		Elements parts = this.select("#maininfo .coverecom .tabstit a");
		if(parts.size()>1){
			String type = parts.get(1).text();
			System.out.println("【Type】:"+type);
			this.entity.setNovelType(type);
		}
	}
	
	public static void main(String[] args) {
		GeilixswDetail detail = new GeilixswDetail("http://www.geilixsw.com/book/41159/");
		detail.test();
	}



}
